package com.umeng.soexample.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBUtils  extends SQLiteOpenHelper {


    public DBUtils(Context context) {
        super(context, "YH.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table user (user_id text, nick_name text, qr_code text, user_name text unique, user_pwd text, user_sex text, user_birthday text, user_height text, user_weight text, user_head text)");
        db.execSQL("create table collection (goodsid text, goods_img text, goods_name text, goods_price text)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    //增加数据
    public long insert(String tableNmae, ContentValues values){

        long insert = getWritableDatabase().insert(tableNmae, null, values);
        return insert;
    }

    //删除数据
    public int delete(String tableNmae, String whereClause, String[] whereArgs){
        int delete = getWritableDatabase().delete(tableNmae, whereClause, whereArgs);
        return delete;
    }

    //修改数据
    public int update(String tableNmae, ContentValues values, String whereClause, String[] whereArgs){
        int update = getWritableDatabase().update(tableNmae, values, whereClause, whereArgs);
        return update;
    }

    //查询数据
    public Cursor query(String tableNmae, String whereClause, String[] whereArgs){
        Cursor query = getWritableDatabase().query(tableNmae, null, whereClause, whereArgs, null, null, null);
        return query;
    }

}
